package com.linx.notice.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.web.core.BaseController;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.notice.domain.vo.InfoRealeaseVo;
import com.linx.notice.domain.bo.InfoRealeaseBo;
import com.linx.notice.service.IInfoRealeaseService;
import com.linx.common.mybatis.core.page.TableDataInfo;

/**
 * 信息发布
 *
 * @author 泽智科技
 * @date 2024-10-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/notice/realease")
public class InfoRealeaseController extends BaseController {

    private final IInfoRealeaseService infoRealeaseService;

    /**
     * 查询信息发布列表
     */
    @SaCheckPermission("notice:realease:list")
    @GetMapping("/list")
    public TableDataInfo<InfoRealeaseVo> list(InfoRealeaseBo query, PageQuery pageQuery) {

        return infoRealeaseService.queryPageList(query, pageQuery);
    }

    /**
     * 导出信息发布列表
     */
    @SaCheckPermission("notice:realease:export")
    @Log(title = "信息发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(InfoRealeaseBo bo, HttpServletResponse response) {
        List<InfoRealeaseVo> list = infoRealeaseService.queryList(bo);
        ExcelUtil.exportExcel(list, "信息发布", InfoRealeaseVo.class, response);
    }

    /**
     * 获取信息发布详细信息
     *
     * @param infoReleaseId 主键
     */
    @SaCheckPermission("notice:realease:query")
    @GetMapping("/{infoReleaseId}")
    public R<InfoRealeaseVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long infoReleaseId) {
        return R.ok(infoRealeaseService.queryById(infoReleaseId));
    }

    /**
     * 新增信息发布
     */
    @SaCheckPermission("notice:realease:add")
    @Log(title = "信息发布", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody InfoRealeaseBo bo) {
        return toAjax(infoRealeaseService.insertByBo(bo));
    }

    /**
     * 修改信息发布
     */
    @SaCheckPermission("notice:realease:edit")
    @Log(title = "信息发布", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody InfoRealeaseBo bo) {
        return toAjax(infoRealeaseService.updateByBo(bo));
    }

    /**
     * 删除信息发布
     *
     * @param infoReleaseIds 主键串
     */
    @SaCheckPermission("notice:realease:remove")
    @Log(title = "信息发布", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoReleaseIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] infoReleaseIds) {
        return toAjax(infoRealeaseService.deleteWithValidByIds(List.of(infoReleaseIds), true));
    }
}
